from sklearn.feature_extraction.text import CountVectorizer
from sklearn.model_selection import train_test_split
import pandas as pd
from sklearn.neural_network import MLPClassifier
from sklearn.metrics import precision_score
from sklearn.metrics import accuracy_score
from sklearn.metrics import recall_score
from sklearn.metrics import f1_score



df = pd.read_csv('', engine='python')

df['encoded_label']=df.Label.map({'spam':0,'ham':1})


train_data, test_data, train_label, test_label = train_test_split(df.Email,df.encoded_label,train_size=0.7,random_state=1)

count_vector = CountVectorizer(stop_words='english',decode_error='ignore')

train_data = count_vector.fit_transform(train_data)

test_data = count_vector.transform(test_data)



mlp = MLPClassifier(solver='lbfgs', activation='logistic')
mlp.fit(train_data, train_label)
predictions_nn = mlp.predict(test_data)




print('神经网络准确率:', format(accuracy_score(test_label, predictions_nn)))
print('神经网络精确率:', format(precision_score(test_label, predictions_nn)))
print('神经网络召回率:', format(recall_score(test_label, predictions_nn)))
print('神经网络 F1 分数:', format(f1_score(test_label, predictions_nn)))
